﻿#pragma once
#include "Rect_Iterator.h"
#include "Vec.h"


class FRect
{
public:

	FVec pos;
	FVec size;

	int x() { return pos.x; } //左上角
	int y() { return pos.y; } //左上角
	int width() { return size.x; };
	int height() { return size.y; };

	int left() { return FMath::Min(x(), x() + width()); }
	int right() { return FMath::Max(x(), x() + width()); }
	int top() { return FMath::Min(y(), y() + height()); }
	int bottom() { return FMath::Max(y(), y() + height()); }

	FVec topleft() { return *new FVec(left(), top()); }
	FVec topRight() { return *new FVec(right(), top()); }
	FVec bottomLeft() { return *new FVec(left(), bottom()); }
	FVec bottomRight() { return *new FVec(right(), bottom()); }

	FVec center() { new FVec((left() + right()) / 2, (top() + bottom()) / 2); }

	bool Contains(FVec point)
	{
		if (point.x < pos.x) return false;
		if (point.x >= pos.x + size.x) return false;
		if (point.y < pos.y) return false;
		if (point.y >= pos.y + size.y) return false;

		return true;
	}

	TArray<FVec> Trace(int direction = -1);

	FRect(int x, int y, int width, int height);

public:
	FRect_Iterator begin() { return FRect_Iterator(*this, 0); }
	FRect_Iterator end() { return FRect_Iterator(*this, 1); }
};